import java.util.concurrent.TimeUnit;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: rei
 * Date: 2025-11-05
 * Time: 21:21
 */
public class Test2 {
    public static void main(String[] args) {
        MyBlockingQueue queue = new MyBlockingQueue(100);
        //一个生产者,一个消费者  生产快消费慢
        Thread producer = new Thread(() ->{
            int num = 0;
            while(true){
                try{
                    TimeUnit.SECONDS.sleep(2);
                    queue.put(num);
                    System.out.println("放入一个元素.....");
                    num++;
                }catch(InterruptedException e){
                    e.printStackTrace();
                }

            }
        });

        producer.start();
        //消费者消费,
        Thread consumer = new Thread(() ->{
            while (true){
                try {
                    TimeUnit.SECONDS.sleep(3);
                    queue.take();
                    System.out.println("拿走一个元素...");
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        });

        consumer.start();













    }
}
